//
//  CouponManagerCell.m
//  GasBusiness
//
//  Created by zfc on 2021/8/1.
//

#import "CouponManagerCell.h"

@interface CouponManagerCell ()

@property (nonatomic, strong) UILabel *moneyLab;
@property (nonatomic, strong) UILabel *typeLab;
@property (nonatomic, strong) UILabel *timeLab;
@property (nonatomic, strong) UILabel *stockLab;


@end

@implementation CouponManagerCell

- (void)awakeFromNib {
    [super awakeFromNib];
}

- (void)setUI {
    self.contentView.backgroundColor = ColorF5;
    UIView *backView = [[UIView alloc] init];
    backView.cornerRadius = 8;
    backView.backgroundColor = WhiteColor;
    [self.contentView addSubview:backView];
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.contentView);
        make.leading.equalTo(self.contentView).offset(15);
        make.top.equalTo(self.contentView).offset(10);
    }];

    UILabel *moneyLab = [[UILabel alloc] init];
    moneyLab.text = @"¥";
    moneyLab.textColor = Color333;
    moneyLab.textAlignment = NSTextAlignmentCenter;
    moneyLab.font = [UIFont systemFontOfSize:40 weight:UIFontWeightBold];
    [backView addSubview:moneyLab];
    self.moneyLab = moneyLab;
    [moneyLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(backView);
        make.leading.equalTo(backView);
        make.width.mas_equalTo(100);
    }];

    UIView *lineView = [[UIView alloc] init];
    lineView.backgroundColor = ColorF5;
    [backView addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(backView).offset(70);
        make.height.mas_equalTo(1);
        make.leading.equalTo(backView).offset(125);
        make.trailing.equalTo(backView).offset(-12);
    }];

    UILabel *typeLab = [[UILabel alloc] init];
    typeLab.text = @"";
    typeLab.font = [UIFont systemFontOfSize:16 weight:UIFontWeightBold];
    typeLab.textColor = Color333;
    [backView addSubview:typeLab];
    self.typeLab = typeLab;
    [typeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(backView).offset(14);
        make.leading.equalTo(backView).offset(125);
    }];

    UILabel *timeLab = [[UILabel alloc] init];
    timeLab.text = @"";
    timeLab.font = [UIFont systemFontOfSize:12 weight:UIFontWeightMedium];
    timeLab.textColor = Color666;
    [backView addSubview:timeLab];
    self.timeLab = timeLab;
    [timeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(backView).offset(40);
        make.leading.equalTo(backView).offset(125);
        make.trailing.equalTo(backView).offset(-10);
    }];

    UILabel *stockLab = [[UILabel alloc] init];
    stockLab.text = @"";
    stockLab.font = [UIFont systemFontOfSize:12 weight:UIFontWeightMedium];
    stockLab.textColor = Color999;
    [backView addSubview:stockLab];
    self.stockLab = stockLab;
    [stockLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(backView).offset(-14);
        make.leading.equalTo(backView).offset(125);
    }];


    UIButton *givebtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [givebtn setTitle:@"赠送" forState:UIControlStateNormal];
    [givebtn setTitleColor:WhiteColor forState:UIControlStateNormal];
    givebtn.titleLabel.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
    givebtn.cornerRadius = 5;
    givebtn.backgroundColor = ThemeColor;
    [backView addSubview:givebtn];
    self.givebtn = givebtn;
    [givebtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.equalTo(backView).offset(-13);
        make.bottom.equalTo(backView).offset(-7);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(24);
    }];
}

- (void)setDic:(NSDictionary *)dic {
    _dic = dic;

    self.moneyLab.text = [NSString stringWithFormat:@"%@", dic[@"discount"]];
    self.typeLab.text = dic[@"title"];
    self.timeLab.text = [NSString stringWithFormat:@"有效时间:%@-%@", [Untils setTimeWithTime:dic[@"start_time"] format:@"yyyy.MM.dd"], [Untils setTimeWithTime:dic[@"end_time"] format:@"yyyy.MM.dd"]];
    self.stockLab.text = [NSString stringWithFormat:@"剩余%@张", dic[@"count"]];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

}

@end
